package com.ziyun.erp.web.api.purchase;

import com.ziyun.erp.modules.material.entity.MaterialEntity;
import com.ziyun.erp.modules.material.service.MaterialCategoryService;
import com.ziyun.erp.modules.material.service.MaterialService;
import com.ziyun.erp.modules.purchase.entity.StorePurchaseApplyDetailEntity;
import com.ziyun.erp.modules.purchase.entity.StorePurchaseApplyEntity;
import com.ziyun.erp.modules.purchase.entity.dto.StorePurchaseApplyDto;
import com.ziyun.erp.modules.purchase.service.StorePurchaseApplyDetailService;
import com.ziyun.erp.modules.purchase.service.StorePurchaseApplyService;
import com.ziyun.erp.web.modules.capital.controller.QueryPage;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 门店采购申请表
 *
 * @author guizhao
 * @email 
 * @date 2018-09-26 13:28:47
 */
@RestController
@RequestMapping("port/purchase/storepurchaseapply")
public class StorePurchaseApplyControllerApi {

    @Autowired
    private StorePurchaseApplyService storePurchaseApplyService;
    @Autowired
    private MaterialCategoryService materialCategoryService;
    @Autowired
    private MaterialService materialService;
    @Autowired
    private StorePurchaseApplyDetailService storePurchaseApplyDetailService;

    /**
     * 列表
     */
    @RequestMapping("/querylistPage")
    public R querylistPage(@RequestBody QueryPage<StorePurchaseApplyEntity> query){
        storePurchaseApplyService.querylistPage(query.getPage(),query.getParams());
        return R.ok().put("page", query.getPage());
    }

    /**
     * 获取枚举类信息
     */
    @RequestMapping("/getEnumList")
    public R getEnumList(){
        return materialCategoryService.getTree();
    }

    /**
     * 列表
     */
    @RequestMapping("/queryMaterialsList")
    public R queryMaterialsList(@RequestBody QueryPage<MaterialEntity> query ) {
        materialService.queryMaterialsListPage(query.getPage(),query.getParams());
        return R.ok().put("page", query.getPage());
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StorePurchaseApplyDto storePurchaseApplyDto){
        return storePurchaseApplyService.insertApply(storePurchaseApplyDto);
    }

    /**
     * 采购明细
     */
    @RequestMapping("/queryList/{applyId}")
    public R queryList(@PathVariable("applyId") Integer applyId){
        List<StorePurchaseApplyDetailEntity> storePurchaseApplyDetailEntityList = storePurchaseApplyDetailService.queryList(applyId);
        return R.ok().put("storePurchaseApplyDetailEntityList",storePurchaseApplyDetailEntityList);
    }

}
